$(document).ready(function(e) {
    var email = window.localStorage.getItem("#email");
    var password = window.localStorage.getItem("#password");
    $("#email").val(email);
    $("#password").val(password);
    // var state = false;
    // $("#email").focus(function () {
    //     if (state == false) {
    //         $(this).val('');
    //     }
    // })
    $("#next").click(function(e) {
        var email = $("#email").val();
        var password = $("#password").val();
        if(email==""){
            alert("邮箱不能为空");
            return;
            }

            if (/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(email) == false) {
                alert("邮箱格式不正确，请重新输入");
                return;
            }

        if(password==""){
            alert("密码不能为空");
            return;
        }
        // var ischeck=$("#checkboxId").is(':checked');
        // if(ischeck){
        //     deleteInfo();
        //     saveInfo(phoneNo,password);
        // }
        var ischeck=$("#checkboxId").is(':checked');
        if(ischeck){
            deleteInfo();
            saveInfo(email,password);
        }
        $("#next").css("background","#ccc");
        $("#next").attr("disabled",true);
        var loginEntity= {};
        loginEntity['userEmail']=email;
        loginEntity['password']=password;
        $.ajax({
            url: 'loginController',
            method: 'post',
            contentType: 'application/json', // 这句不加出现415错误:Unsupported Media Type
            data: JSON.stringify(loginEntity), // 以json字符串方式传递
            success: function(data) {
                if(data=="email not register"){
                    alert(data);

                    }else if(data=="password is error"){
                        alert(data);

                    }else{
                        url="toMessage";
                        window.location.href=url;

                }
                $("#next").attr("disabled", false)
            },
            error: function(data) {
                console.log("error...");
                $("#next").attr("disabled", false)
            }
        });
    });

    function saveInfo(email,password){
        window.localStorage.getItem("#email");
        window.localStorage.setItem( "#email", email );
        window.localStorage.getItem("#password");
        window.localStorage.setItem( "#password", password );
    }

    function deleteInfo(){
        window.localStorage.removeItem( "#email" );
        window.localStorage.clear();
        window.localStorage.removeItem( "#password" );
        window.localStorage.clear();
    }
})
function toregister(){
    // location.href="toRegisterAction.action";
    location.href="toRegister";
}
